/**
 * 初始化资金预算详情对话框
 */
var CapitalBudgetInfoDlg = {
    capitalBudgetInfoData : {}
};

/**
 * 清除数据
 */
CapitalBudgetInfoDlg.clearData = function() {
    this.capitalBudgetInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
CapitalBudgetInfoDlg.set = function(key, val) {
    this.capitalBudgetInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
CapitalBudgetInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
CapitalBudgetInfoDlg.close = function() {
    parent.layer.close(window.parent.CapitalBudget.layerIndex);
}

/**
 * 收集数据
 */
CapitalBudgetInfoDlg.collectData = function() {
    this
    .set('id')
    .set('platform')
    .set('projectid')
    .set('type')
    .set('budgetAmount')
    .set('rmb')
    .set('remarks')
    .set('revDate')
    .set('creattime')
    .set('updatetime');
}

/**
 * 提交添加
 */
CapitalBudgetInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/capitalBudget/add", function(data){
        Feng.success("添加成功!");
        window.parent.CapitalBudget.table.refresh();
        CapitalBudgetInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.capitalBudgetInfoData);
    ajax.start();
}




/**
 * 提交修改
 */
CapitalBudgetInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/capitalBudget/update", function(data){
        Feng.success("修改成功!");
        window.parent.CapitalBudget.table.refresh();
        CapitalBudgetInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.capitalBudgetInfoData);
    ajax.start();
}


/**
 * 上传文件
 */
CapitalBudgetInfoDlg.uploadSubmit = function() {debugger
    console.log(document.getElementById('inPut').files)
    var inputData = document.getElementById('inPut').files[0]
    var formData = new FormData();
    formData.append("file",inputData);
    $.ajax({
        url: "/capitalBudget/upload",
        data: formData,
        type: "Post",
        dataType: "json",
        cache: false,//上传文件无需缓存
        processData: false,//用于对data参数进行序列化处理 这里必须false
        contentType: false, //必须
        success:function () {
            alert("上传成功！");
        },
        error:function (data) {
            alert("上传失败"+data.responseJSON.message + "!");
        }
    });


}

$(function() {

});
